<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <div class="contentsize">当前待办</div>
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-form ref="searchform" :model="searchform" label-width="auto" :inline="true" size="mini">
                    <el-form-item label="档案编号:">
                        <div style="width: 170px">
                            <el-input v-model="searchform.dabh" placeholder="请输入档案编号"
                                @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="房屋地址:">
                        <div style="width: 170px">
                            <el-input v-model="searchform.dz" placeholder="请输入房屋地址"
                                @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="所属事务:">
                        <div style="width: 170px">
                            <el-select v-model="searchform.processcode" placeholder="请选择所属事务" @change="onSearch">
                                <el-option v-for="item in ssswlist" :key="item.code" :label="item.name"
                                    :value="item.code"> </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSearch" icon="el-icon-search"
                            class="searchcolor">查询</el-button>
                        <el-button @click="reSearch" icon="el-icon-refresh" class="searchcolor">重置</el-button>
                        <!-- v-if="role == '10013' || role == '10001'" -->
                        <el-button @click="shlist" type="primary"
                            :disabled="multipleSelection.length == 0" v-if="role == '10013' || role == '10001'">批量审核</el-button>
                        <!-- <el-button type="primary" @click="downloadlist" icon="el-icon-download"
                            class="searchcolor">导出</el-button> -->
                    </el-form-item>
                </el-form>
            </div>
            <!-- max-height="330" -->
            <el-table :data="tableData" style="width: 100%" :header-cell-style="tableHeaderColor"
                :row-style="tablerowColor" :row-class-name="tableRowClassName" :cell-style="tablecellColor" border
                :max-height="maxHeight" @selection-change="handleSelectionChange"
                v-if="role == '10013' || role == '10001'">
                <!-- v-if="role == '10013' || role == '10001'" -->
                <el-table-column type="selection" width="55" fixed >
                </el-table-column>
                <el-table-column prop="bz" label="当前节点" align="center" width="300"> </el-table-column>
                <el-table-column prop="sssw" label="所属事务名称" align="center" width="300"> </el-table-column>
                <el-table-column prop="dz" label="地址" align="center" width="200" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="addusername" label="发起人" align="center" width="160"> </el-table-column>
                <el-table-column prop="adddatetime" label="发起日期" align="center" width="120">
                    <template slot-scope="scope">
                        {{ scope.row.adddatetime ? scope.row.adddatetime.split(' ')[0] : '' }}
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="100" align="center">
                    <template slot-scope="scope">
                        <el-button type="text" size="small"
                            @click="gotofwjg(scope.row.processcode, scope.row.id)">办理</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-table :data="tableData" style="width: 100%" :header-cell-style="tableHeaderColor"
                :row-style="tablerowColor" :row-class-name="tableRowClassName" :cell-style="tablecellColor" border
                :max-height="maxHeight" v-else>
                <el-table-column prop="bz" label="当前节点" align="center"> </el-table-column>
                <el-table-column prop="sssw" label="所属事务名称" align="center"> </el-table-column>
                <el-table-column prop="dz" label="地址" align="center" width="200" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="addusername" label="发起人" align="center"> </el-table-column>
                <el-table-column prop="adddatetime" label="发起日期" align="center">
                    <template slot-scope="scope">
                        {{ scope.row.adddatetime ? scope.row.adddatetime.split(' ')[0] : '' }}
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="100" align="center">
                    <template slot-scope="scope">
                        <el-button type="text" size="small"
                            @click="gotofwjg(scope.row.processcode, scope.row.id)">办理</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination" style="float: right">
                <el-pagination background layout="total,prev, pager, next,jumper" :total="total"
                    :current-page.sync="current" :page-size="pageSize" @current-change="handleCurrentChange">
                </el-pagination>
            </div>
            <!-- 批量审核 -->
            <el-dialog title="批量审核" :visible.sync="addlistval" :modal-append-to-body="false" center width="60%">
                <!-- :close-tab.sync="addlistval" -->
                <baseinfo :detailform="detailform" :form="form" @close-tab="closetab" :multipleSelection="multipleSelection" :userlist="userlist" :activeName = "activeName"></baseinfo>
            </el-dialog>
        </div>
    </div>
</template>

<script>
// 10013 10001这俩批量审核
import { dbnodelist, dbnodelete, exportBuildlist, alldetails } from '@/api/index';
import valueList from '@/components/common/valueList.vue';
import baseinfo from '@/components/spfile/baseinfo.vue'
export default {
    components: {
        baseinfo
    },
    name: 'fwjglist',
    data() {
        return {
            activeName: 'first',
            userlist:[],
            spidcs: '',
            detailform:{},
            addlistval: false,
            ssswlist: valueList.ssswlist, //所属事物列表
            total: 0,
            current: 1,
            pageSize: 10,
            searchform: {
                adddatetime: '', // 发起日期 ,
                adduser: '', // 发起人ID ,
                addusername: '', // 发起人姓名 ,
                bz: '', // 步骤（当前节点） ,
                current: 1, //第几页 ,
                dabh: '', // 档案编号 ,
                dz: '', // 地址 ,
                id: '', // id ,
                pageSize: 10, // 每页数量 ,
                processcode: 'fwjg', // 流程模板编码(例：fwjg) 所属事务编码 ,
                sssw: '', // 所属事务名称 ,
                userid: this.$store.getters.userId, // 当前用户ID
                lcfl: '1'
            },
            tableData: [],
            maxHeight: null,
            role: this.$store.getters.role,
            multipleSelection: [],
            form: {},
            yjdeepcolor: null,
            yjlist: ['同意', '同意，请认真办理！', '拟同意，请领导批示！', '请办公室盖章！', '已盖章', '已办理，请归档！'],
            role: this.$store.getters.role,
            yjlistld: [
                '拟同意，请智宗同志阅示！',
                '同意',
                '同意，请认真办理！',
                '拟同意，请领导批示！',
                '请办公室盖章！',
                '已盖章',
                '已办理，请归档！'
            ],
            yjlistnq: [
                '已归档',
                '请盖章',
                '同意',
                '同意，请认真办理！',
                '拟同意，请领导批示！',
                '请办公室盖章！',
                '已盖章',
                '已办理，请归档！'
            ],
            yjlistht: ['不同意', '不同意，请认真复核！'],
        };
    },
    computed: {},
    methods: {
        shlist() {
            // 点击出弹框
            if (this.multipleSelection.length > 0) {
                let data ={ id:this.multipleSelection[0].id}
                this.alldetails(data)
                // this.spidcs=this.multipleSelection[0].id
                this.addlistval = true
            }
        },
        // 多条报账点击事件
        handleSelectionChange(val) {
            console.log('val', val);
            this.multipleSelection = val;
        },
        alldetails(data) {
            var that = this;
            alldetails(data).then((res) => {
                this.addlistval = true
                console.log('res', res);
                this.detailform = res.data; //全部数据
                if (res.data.nextnodelist.length != 0) {
                    that.form.nextnodeid = res.data.nextnodelist[0].id;
                    that.userlist = res.data.nextnodelist[0].userlist;
                    that.form.selectuser = that.userlist[0].id;
                }
            });
        },
        // 关闭弹框刷新页面
        closetab() {
            this.addlistval = false
            this.current = 1;
            this.dbnodelist(this.searchform);
        },
        // 列表样式
        tableHeaderColor({ row, column, rowIndex, columnIndex }) {
            if (rowIndex === 0) {
                return 'background:linear-gradient(to bottom, #008A94,#0ae2f2)!important;color:#ffffff;font-size:14px;';
            }
        },
        tablerowColor({ row, rowIndex }) {
            return 'height: 42px;font-size:14px;color:black';
        },
        tablecellColor() {
            return 'font-weight:700;color:#000000;border-color:#c0c0c0';
        },
        tableRowClassName({ row, rowIndex }) {
            if (rowIndex % 2 != 0) {
                return 'success-row'; //这是类名
            } else {
                return '';
            }
        },
        // 换页
        handleCurrentChange(val) {
            this.current = val;
            this.searchform.current = val;
            this.dbnodelist(this.searchform);
            console.log(val);
        },
        // 搜索
        onSearch() {
            this.current = 1;
            this.searchform.current = 1;
            this.dbnodelist(this.searchform);
            console.log('搜索');
        },
        // 重置
        reSearch() {
            this.current = 1;
            this.searchform = {
                adddatetime: '', // 发起日期 ,
                adduser: '', // 发起人ID ,
                addusername: '', // 发起人姓名 ,
                bz: '', // 步骤（当前节点） ,
                current: 1, //第几页 ,
                dabh: '', // 档案编号 ,
                dz: '', // 地址 ,
                id: '', // id ,
                pageSize: 10, // 每页数量 ,
                processcode: '', // 流程模板编码(例：fwjg) 所属事务编码 ,
                sssw: '', // 所属事务名称 ,
                userid: this.$store.getters.userId // 当前用户ID
            };
            this.dbnodelist(this.searchform);
            console.log('搜索');
        },
        // 项目列表
        dbnodelist(data) {
            dbnodelist(data).then((res) => {
                if (res.code == 200) {
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                } else {
                    this.tableData = [];
                    this.total = 0;
                }
            });
        },
        // 删除
        deleteClick(e) {
            console.log(e);
            this.$confirm('确定删除此条信息吗？')
                .then(() => {
                    let data = { id: e.id };
                    dbnodelete(data).then((res) => {
                        if (res.code == 200) {
                            this.dbnodelist(this.searchform);
                            this.$message.success('删除成功');
                        }
                    });
                })
                .catch(() => {
                    this.$message.success('删除取消');
                });
        },
        // 跳转流程页面
        gotofwjg(val, id) {
            if (val == 'jlbqtht1' || val == 'jlbqtht2') {
                this.$router.push({
                    // name: val,
                    name: 'qtht',
                    params: {
                        id: id
                    }
                });
            } else {
                let firstThree = val.substring(0, 3); // 获取前三个字符
                let rest = val.substring(3); // 获取剩余的字符
                this.$router.push({
                    // name: val,
                    name: firstThree == 'jlb' ? rest : val,
                    params: {
                        id: id
                    }
                });
            }
        },
        // 导出
        downloadlist() {
            return;
            exportBuildlist(this.searchform).then((res) => {
                console.log(res);
                const link = document.createElement('a');
                let blob = new Blob([res], {
                    type: 'application/vnd.ms-excel'
                });
                link.style.display = 'none';
                //设置连接
                link.href = URL.createObjectURL(blob);
                link.download = '楼幢导出文件';
                document.body.appendChild(link);
                //模拟点击事件
                link.click();
                console.log(res);
            });
        }
    },
    mounted() {
        this.$nextTick(() => {
            // window.innerHeight 浏览器窗口的可见高度，下面的 420 是除了table最大高度的剩余空间。
            this.maxHeight = window.innerHeight - 360;
        });
        console.log(this.$store.getters);
        this.dbnodelist(this.searchform);
        console.log(valueList);
    }
};
</script>

<style scoped>
/* 选择意见 */
.xzyj {
    width: 48%;
    height: 110px;
    overflow-y: scroll;
    overflow-x: hidden;
    border: 1px solid #dcdfe6;
    border-radius: 4px;
    padding: 10px 0;
    box-sizing: border-box;
}

.xzyj .xzyjitem {
    text-align: left;
    cursor: pointer;
    line-height: 24px;
}

.table-1 {
    border: 1px solid #c0c0c0;
    border-collapse: collapse;
    width: 100%;
    /*合并相邻表格的间距*/
}

.table-1 tr,
.table-1 td {
    font-size: 13px;
    border-collapse: collapse;
    border: 1px solid #c0c0c0;
    padding: 10px;
    box-sizing: border-box;
    color: #606266;
}

.container {
    /* height: calc(100vh - 260px); */
    overflow: hidden;
}

.crumbs {
    background-color: #fff;
    padding: 20px 20px;
}

.indexTitle {
    margin-bottom: 20px;
}

.contentsize {
    font-size: 18px;
    font-weight: 700;
}

.handle-box {
    overflow: hidden;
}

/* 新增按钮 */
.addcolor {
    margin-bottom: 10px;
}

.unloadTitle {
    text-align: left;
    padding-bottom: 10px;
    box-sizing: border-box;
    color: #606266;
}
</style>
<style>
.success-row {
    background-color: #eaf3fb !important;
}
</style>
